from selenium  import webdriver
# 想法： 通过web登录后获取cookies验证是否与浏览器的一致
# 结论: 登录需要手动滑动图片验证，无法模拟20240720
url = 'https://data.eastmoney.com/bkzj/'
headers  = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
    'Host': 'data.10jqka.com.cn',
    'referer': 'https://www.10jqka.com.cn/'
    # 'Cookie':'Hm_lvt_722143063e4892925903024537075d0d=1721390901; Hm_lvt_929f8b362150b1f77b477230541dbbc2=1721390901; Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1721390901; Hm_lvt_60bad21af9c824a4a0530d5dbf4357ca=1721390904; Hm_lvt_f79b64788a4e377c608617fba4c736e2=1721390904; v=A_B2Rk8jYmiIfT5staTyqAffwbVHOdSD9h0oh-pBvMsepZ7rkkmkE0Yt-BY5'

        # 'Hm_lvt_722143063e4892925903024537075d0d=1721390901; '
        #       'Hm_lvt_929f8b362150b1f77b477230541dbbc2=1721390901; '
        #       'Hm_lvt_78c58f01938e4d85eaf619eae71b4ed1=1721390901; '
        #       'Hm_lvt_60bad21af9c824a4a0530d5dbf4357ca=1721390914; '
        #       'Hm_lvt_f79b64788a4e377c608617fba4c736e2=1721390914; '
        #       'Hm_lpvt_722143063e4892925903024537075d0d=1721394512; '
        #       'Hm_lpvt_929f8b362150b1f77b477230541dbbc2=1721394512; '
        #       'Hm_lpvt_60bad21af9c824a4a0530d5dbf4357ca=1721395914; '
        #       'Hm_lpvt_78c58f01938e4d85eaf619eae71b4ed1=1721395914; '
        #       'Hm_lpvt_f79b64788a4e377c608617fba4c736e2=1721395914; '
        #       'log=; '
        #       'HMACCOUNT=FFE4A3ECF588E087; '
        #       'v=A_N1z7BSkQPhal1U-7Wh0fCegvwYKIeBQbzLHqWQT5JJpB3iLfgXOlGMWy-2'

    # 这里可以添加更多的header信息
}

# 启动Chrome浏览器
driver = webdriver.Edge()
# 打开网页

driver.get(url)
print(driver.page_source)
cookies = driver.get_cookies()
str = ''
for cookie in cookies:
    str = str + cookie['name'] + '=' + cookie['value'] + ';'
print(str)
# str =  'log=; u_ukey=A10702B8689642C6BE607730E11E6E4A; u_uver=1.0.0; u_dpass=bqkFClseEeSnRKkMcwSbtq3dfetiAgAiDiu934XKOe5vmS3FP72SbsKj3Yu%2BAW5%2BHi80LrSsTFH9a%2B6rtRvqGg%3D%3D; u_did=A56AAF622DC943098695F93CC0D14D99; u_ttype=WEB;'
# str = str + 'log=; u_ukey=A10702B8689642C6BE60o730E11E6E4A; u_uver=1.0.0; u_dpass=bqkFClseEeSnRKkMcwSbtq3dfetiAgAiDiu934XKOe5vmS3FP72SbsKj3Yu%2BAW5%2BHi80LrSsTFH9a%2B6rtRvqGg%3D%3D; u_did=A56AAF622DC943098695Fo3CC0D14D99; u_ttype=WEB;'
headers.setdefault('Cookie', str)
print(headers)